package com.example.rabbit.util;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author ifredomvip@gmail.com
 * @Date 2022/8/5 11:15
 * @Version 1.0.0
 * @Description
 **/
public class RabbitMqUtils {
    public static Channel channel;

    public static Channel getChannel() throws IOException, TimeoutException {

        if (channel == null) {
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("39.103.174.51");
            factory.setUsername("ifredom");
            factory.setPassword("123456");

            Connection connection = factory.newConnection();

            channel = connection.createChannel();
            return channel;
        }

        return channel;

    }

}
